/*************************************************************************
 * File Name:    Plus_One.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: 2013-11-6 13:41:22
 * 
 * Description:  
 |-----------------------------------------------------------------------
 | Problem: Plus One
 | Given a number represented as an array of digits, plus one to the number.
 |-----------------------------------------------------------------------
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>

using namespace std;

class Solution {
public:
    vector<int> plusOne(vector<int> &digits)
    {
        deque<int> ans(digits.begin(), digits.end());
        int N = digits.size();
        
        ++ans[N - 1];
        for (int i = N - 1; i >= 1; --i) {
            ans[i - 1] += ans[i] / 10;
            ans[i] %= 10;
        }
        if (ans[0] >= 10) {
            ans[0] %= 10;
            ans.push_front(1);
        }
        return vector<int>(ans.begin(), ans.end());
    }
};

